#include <iostream>
using namespace std;

typedef long long LL;
const int N = 1e5 + 10;

int n;
char s[N];
LL f[26];
LL g[26];

int main()
{
    cin >> n >> s;
    LL ans = 0;
    for (int i = 0; i < n; i++)
    {
        int x = s[i] - 'a';
        ans += f[x];

        f[x] = f[x] + i - g[x];
        g[x] = g[x] + 1;
    }
    cout << ans << endl;
    return 0;
}